package com.hqyj.controller;

import com.hqyj.pojo.*;
import com.hqyj.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AjaxController {
    @Autowired
    UserService userService;

    @Autowired
    AfterServices afterServices;

    @Autowired
    TransactionService transactionService;

    @Autowired
    CustomerService customerService;
    @RequestMapping("/userAjax/{url}")
    public DataMessage userAjax(@PathVariable("url")String url, User user){
        switch (url){
            case "login":
                return userService.login(user);
            case "list":
                return userService.queryAll(user);
            case "list3":
                return userService.queryAllTwo(user);
            case "list4":
                return userService.queryAllSales(user);
            case "update":
                return userService.updateByUserId(user);
            case "delete":
                return userService.updateDeleteByUserId(user);
            case "add":
                return userService.add(user);
            case "listByName":
                return userService.queryByName(user);
            case "listUserRole":
                return userService.allUserRole(user);
            case "queryNoRole":
                return userService.queryAllNoRole(user);
            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
    @Autowired
    PublicCustomerService publicCustomerService;
    @RequestMapping("/publicAjax/{url}")
    public DataMessage publicAjax(@PathVariable("url")String url, PublicCustomers publicCustomers) {
        switch (url){
            case "list":
                return publicCustomerService.queryAll(publicCustomers);

            case "add":
                return publicCustomerService.add(publicCustomers);
            case "update":
                return publicCustomerService.updateUsrName(publicCustomers);

            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
    @Autowired
    RoleService roleService;
    @RequestMapping("/roleAjax/{url}")
    public DataMessage roleAjax(@PathVariable("url")String url, Role role) {
        switch (url){
            case "list":
                return roleService.queryAll(role);

            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
    @Autowired
    UserRoleService userRoleService;
    @RequestMapping("/userRoleAjax/{url}")
    public DataMessage userRoleAjax(@PathVariable("url")String url, UserRole userRole) {
        switch (url){

            case "update":
                return userRoleService.updateRole(userRole);
            case "add":
                return userRoleService.add(userRole);
            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }

    @RequestMapping("/vipAjax/{url}")
    public DataMessage vipAjax(@PathVariable("url") String url, Customer c,Order o,User user){
        switch (url){
            case "list":
                return customerService.list(c);
            case "add":
                return transactionService.Add(o,c);
            case "update":
                return customerService.update(c);
            case "name":
                    return userService.name(user);
            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
    //订单
    @RequestMapping("/tstAjax/{url}")
    public DataMessage TransactionAjax(@PathVariable("url") String url, Order o,Customer c){

        switch (url){
            case "list" :
                return transactionService.list(o);
            case "update" :
                return transactionService.update(o);
            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
    //售后
    @RequestMapping("/afterAjax/{url}")
    public DataMessage afterAjax(@PathVariable("url") String url ,AfterService a){
        switch (url){
            case "add":
                return afterServices.add(a);
            case "list":
                return afterServices.list(a);
            case "update":
                return afterServices.update(a);
            default:
                DataMessage data = new DataMessage();
                data.setSuccess(false);
                data.setInfo("请求地址不正确");
                return data;
        }
    }
}
